<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__purchasedetail}">
      <div class="ba-operate-form">
        <el-form :model="dataForm" @keyup.enter.native="getDataList()" label-width="70px">
          <el-row :gutter="20">
            <el-col :md="8" :sm="8">
              <el-form-item label="托盘条码">
                <el-input v-model="dataForm.contNo" placeholder="精确匹配" maxlength="32" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="6">
              <el-form-item label="砂芯图号">
                <el-input v-model="dataForm.spuNo" placeholder="精确匹配" maxlength="20" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="5" :sm="5">
              <el-form-item label="批次">
                <el-input v-model="dataForm.lotNo" placeholder="精确匹配" maxlength="32" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="5" :sm="5">
              <div class="right-handle-group">
                <el-button-group>
                  <el-button @click="getDataList()" type="primary">{{ $t('query') }}</el-button>
                  <el-button @click="getReset()">{{ $t("reset") }}</el-button>
                  <el-tooltip class="item" effect="dark" content="高级搜索" placement="top-start">
                    <el-button @click="advanced = !advanced" color="#dcdfe6" icon="el-icon-search" plain></el-button>
                  </el-tooltip>
                </el-button-group>
              </div>
            </el-col>
          </el-row>
          <el-collapse-transition>
            <div v-show="advanced">
              <el-row :gutter="20">
                <el-col :md="12" :sm="12">
                  <el-form-item label="创建日期">
                    <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange"
                      range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                      :picker-options="pickerOptions">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :md="6" :sm="9">
                  <el-form-item label="明细状态">
                    <el-select v-model="dataForm.detailSt" placeholder="可选状态">
                      <el-option v-for="item in statusOption" :key="item.dictValue" :label="item.dictLabel"
                        :value="item.dictValue"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-collapse-transition>
        </el-form>
      </div>

      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
        style="width: 100%">
        <el-table-column prop="detailId" label="id" header-align="center" align="center"></el-table-column>
        <el-table-column prop="purchaseId" label="主单id" header-align="center" align="center"></el-table-column>
        <el-table-column prop="contNo" label="托盘条码" header-align="center" align="center"
          min-width="220"></el-table-column>
        <el-table-column prop="spuNo" label="砂芯图号" header-align="center" align="center"
          min-width="135"></el-table-column>
        <el-table-column prop="lotNo" label="批次" header-align="center" align="center"></el-table-column>

        <el-table-column prop="planQnty" label="计划量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="actlQnty" label="实收量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="detailSt" label="单据状态" header-align="center" align="center" min-width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.detailSt === 0">初始</el-tag>
            <el-tag v-else-if="scope.row.detailSt === 1">收货中</el-tag>
            <el-tag v-else-if="scope.row.detailSt === 2" type="success">已完成</el-tag>
            <el-tag v-else-if="scope.row.detailSt === 9" type="warning">废弃</el-tag>
            <el-tag v-else type="danger">异常</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="creatorName" label="创建用户" header-align="center" align="center"
          show-overflow-tooltip></el-table-column>
        <el-table-column prop="createDate" label="创建日期" header-align="center" align="center"
          min-width="155"></el-table-column>
        <el-table-column prop="updaterName" label="更新用户" header-align="center" align="center"
          show-overflow-tooltip></el-table-column>
        <el-table-column prop="updateDate" label="更新日期" header-align="center" align="center"
          min-width="155"></el-table-column>
        <el-table-column prop="comments" label="备注" header-align="center" align="center"></el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/wms/purchase-detail/page",
        getDataListIsPage: true,
        exportURL: "/wms/purchase-detail/export",
        deleteURL: "/wms/purchase-detail",
        deleteIsBatch: true,
      },
      dataForm: {
        purchaseId: '',
        contNo: '',
        spuNo: '',
        lotNo: '',
        detailSt: '',
        startDate: '',
        endDate: '',
      },
      //日期范围
      dateRange: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "当天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setHours(0, 0, 0);

              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          }
        ]
      },
      advanced: false,
      statusOption: [],
      dictType: "purchase_status",
    };
  },
  created() {
    this.getDetailStatusList();
  },
  methods: {
    //0.重置搜索框
    getReset() {
      this.dataForm = this.$options.data().dataForm;
      this.dateRange = this.$options.data().dateRange;
    },
    //1.获取明细状态描述
    getDetailStatusList() {
      this.$http
        .get(`/sys/dict/type/list`, {
          params: {
            dictType: this.dictType,
          },
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.statusOption = res.data;
        }).catch(() => { });
    },
  }
};
</script>
